<?php
/**
 * Created by PhpStorm.
 * User: kaycn
 * Date: 18-9-13
 * Time: 下午10:49
 */
namespace Facebook\WebDriver;
use Facebook\WebDriver\Remote\DesiredCapabilities;
use Facebook\WebDriver\Remote\RemoteWebDriver;
use Pay\Screen;

require_once('vendor/autoload.php');

header("Content-Type: text/html; charset=UTF-8");
const vcodeDst = 'vcode.png';   //验证码存放地址


// start Firefox with 5 second timeout
$host = 'http://localhost:4444/wd/hub'; // this is the default
$capabilities = DesiredCapabilities::chrome();
$driver = RemoteWebDriver::create($host, $capabilities, 5000);
$driver->get('https://www.alipay.com/');

$element = $driver->findElement(WebDriverBy::cssSelector('.title>.personal'));

$driver->executeScript("arguments[0].click();", [$element]);


// 等待新的页面加载完成....
$driver->wait(2)->until(
    WebDriverExpectedCondition::visibilityOfElementLocated(
        WebDriverBy::id('J_onepage')

    )
);
$element = $driver->findElement(WebDriverBy::cssSelector('.button-login'));

$driver->executeScript("arguments[0].click();", [$element]);

$driver->wait(2)->until(
    WebDriverExpectedCondition::visibilityOfElementLocated(
        WebDriverBy::id("J_loginIframe")

    )
);

//$element = $driver->findElement(WebDriverBy::cssSelector('#J_loginbox>.qrcode-target-hide'));
$driver_old = $driver;
$driver->switchTo()->frame("J_loginIframe");
$str = $driver->getPageSource();
$element = $driver->findElement(WebDriverBy::cssSelector('.qrcode-target-hide'));

$driver->executeScript("arguments[0].click();", [$element]);

$js = <<<js
    document.getElementById("J-checkcode").setAttribute("class","ui-form-item");
js;

$driver->executeScript($js);



sleep(2);
//截取当前网页，该网页有我们需要的验证码




(new Screen($driver))->frame();